package bCommon
{
	import flash.display.DisplayObject;
	
	import mx.core.IFlexDisplayObject;
	import mx.managers.SystemManager;
	
	public class TPopUpManager
	{
		import mx.managers.PopUpManager;
		
		private static var arrayPopUp:Array=new Array();
		public function TPopUpManager()
		{
		}
		
		public static function addPopUp(win:IFlexDisplayObject,parent:DisplayObject,modal:Boolean=false,childList:String=null):void
		{
			if(TPopUpManager.contains(DisplayObject(win)))
			{
				return;
			}
			mx.managers.PopUpManager.addPopUp(win,parent,modal,childList);
			arrayPopUp.push(win);	
		}
		
		public static function centerPopUp(pop:IFlexDisplayObject):void
		{
			mx.managers.PopUpManager.centerPopUp(pop);
		}
		
		public static function bringToFront(pop:IFlexDisplayObject):void
		{
			mx.managers.PopUpManager.bringToFront(pop);
		}
		
		public static function createPopUp(parent:DisplayObject,className:Class,modal:Boolean=false,childList:String=null):IFlexDisplayObject
		{
			var pop=mx.managers.PopUpManager.createPopUp(parent,className,modal,childList);
			arrayPopUp.push(pop);
			return pop;
		}
		
		public static function removePopUp(popUp:IFlexDisplayObject):void
		{
			mx.managers.PopUpManager.removePopUp(popUp);
			for(var pop=0;pop<arrayPopUp.length;pop++)
			{
				if(arrayPopUp[pop]==popUp)
				{
					arrayPopUp.splice(pop,1);
					break;
				}	
			}
		}
		
		public static function get allPopUp():Array
		{
			return arrayPopUp;
		}
		
		public static function contains(popUp:DisplayObject):Boolean
		{
			for(var pop=0;pop<arrayPopUp.length;pop++)
			{
				if(arrayPopUp[pop]==popUp)
				{
					return true;
				}	
			}
			return false;
		}
		
		public static function clearPopUpWindow():void
		{
			var allPopup:Array=TPopUpManager.allPopUp;
			while(allPopup.length)
			{
				TPopUpManager.removePopUp(allPopup.pop());	
			}
		}
		

	}
}